#include "bubblesortclass.h"

#include <QElapsedTimer>

#include <iostream>

BubbleSortClass::BubbleSortClass(QObject* parent) : QObject{ parent }
{
}

void BubbleSortClass::sort(std::vector<int> theData)
{
    QElapsedTimer timer;
    timer.start();
    int temporary;
    for (int i = 0; i < theData.size(); i++)
    {
        for (int j = 0; j < theData.size() - i - 1; j++)
        {
            if (theData[j] > theData[j + 1])
            {
                temporary = theData[j];
                theData[j] = theData[j + 1];
                theData[j + 1] = temporary;
            }
        }
    }
    int millsecond = timer.elapsed();
    std::cout << "冒泡排序用时" << millsecond << "毫秒" << std::endl;

    emit sortResult(theData);
}
